home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Utilities / Siege Watch 2.0 / mySpeech.p < prev    next >
Encoding:
Text File  |  1994-04-23  |  2.2 KB  |  104 lines  |  [TEXT/PJMM]

  1. {}
  2. {     routines related to saying strings }
  3. unit MySpeech;
  4. interface
  5.     uses
  6.         FixMath, Speech, Globals, Daemon;
  7.  
  8.  
  9. { personal prototypes }
  10.     function IsSpeechAvailable: Boolean;
  11.     procedure PlayMySpeech (index: integer);
  12.     procedure SayNumbers (days: LONGINT;
  13.                                     index: integer);
  14.     procedure PlayBites;
  15. { actual code }
  16. implementation
  17.     uses
  18.         Utility;
  19.     const
  20.         gestaltSpeechAttr = 'ttsc';        { Gestalt Manager selector for Speech Attributes }
  21.         gestaltSpeechMgrPresent = 0;    { Gestalt bit which indicates that Speech Manager exists }
  22.         SPEECH_STRINGS = 400;
  23.         BYTE_PROB_NUM = 25000;
  24.  
  25.  
  26.     function IsSpeechAvailable: Boolean;
  27.         var
  28.             response: LONGINT;
  29.             iErr: OSErr;
  30.     begin
  31.         IsSpeechAvailable := FALSE;
  32.         iErr := Gestalt(gestaltSpeechAttr, response);
  33.         if (BitTst(@response, 31 - gestaltSpeechMgrPresent)) and (iErr = 0) then
  34.             begin
  35.                 IsSpeechAvailable := TRUE;
  36.             end;
  37.     end;
  38.  
  39.  
  40.     procedure SayMyString (aString: Str255);
  41.         var
  42.             iErr: OSErr;
  43.             byteLength: LONGINT;
  44.     begin
  45.         if gPreferences.useDaemon then
  46.             begin
  47.                 Talk2Daemon(gPreferences, aString);
  48.             end
  49.         else
  50.             begin
  51.                 iErr := SpeakString(aString);
  52.             end;
  53.     end;
  54.  
  55.     procedure SayNumbers (days: LONGINT;
  56.                                     index: integer);
  57.         var
  58.             theString: Str255;
  59.             dayString: Str255;
  60.     begin
  61.         GetIndString(dayString, SPEECH_STRINGS, index);
  62.         NumToString(days, theString);
  63.         theString := Concat(theString, dayString);
  64.         SayMyString(theString);
  65.     end;
  66.  
  67.     procedure PlayMySpeech (index: integer);
  68.         var
  69.             iErr: OSErr;
  70.             byebyeString: Str255;
  71.     begin
  72.         GetIndString(byebyeString, SPEECH_STRINGS, index);
  73.         SayMyString(byebyeString);
  74.     end; (* PlayMySpeech *)
  75.  
  76.     procedure PlayBites;
  77.         var
  78.             randNum: integer;
  79.             numStrings: integer;
  80.             index: integer;
  81.             aStringH: StringHandle;
  82.     begin
  83.         if gPreferences.sayBites then
  84.             begin
  85.                 randNum := ChooseRandom(0, 32767);
  86.  
  87.                 if randNum < gPreferences.biteFreq then
  88.                     begin
  89.                         numStrings := Count1Resources('BITE');
  90.                         if numStrings > 0 then
  91.                             begin
  92.                                 index := ChooseRandom(1, numStrings);
  93.                                 aStringH := StringHandle(Get1IndResource('BITE', index));
  94.                                 if aStringH <> nil then
  95.                                     begin
  96.                                         SayMyString(aStringH^^);
  97.                                         ReleaseResource(Handle(aStringH));
  98.                                     end;
  99.                             end;
  100.                     end;
  101.             end;
  102.     end;
  103.  
  104. end.